import Player from "./Player";


const { ccclass, property } = cc._decorator;

@ccclass
export default class Enemy extends cc.Component {

    @property(cc.Integer)
    ball_type: number = 0;

    @property(cc.Sprite)
    ball_icon: cc.Sprite = null;

    private target: Player;

    private _power_scale: number = 1;
    public get power_scale() {
        return this._power_scale;
    }
    public set power_scale(value) {
        this._power_scale = value;
        this.ball_icon.node.setScale(value > 1 ? 1.5 : 1);
    }

    protected onLoad(): void {

    }



    update(dt: number): void {
        // let speed = 150
        // let vec = this.target.node.position.sub(this.node.position)
        // vec.normalizeSelf();
        // vec.mulSelf(speed)
        // this.getComponent(cc.RigidBody).linearVelocity = cc.v2(vec.x, vec.y);
    }

    setTarget(target: Player) {
        this.target = target
    }

    reset() {
        this.node.stopAllActions();
        this.getComponent(cc.RigidBody).linearVelocity = cc.v2(0, 0);
        this.power_scale = 1;
        this.node.active = false;
    }


    fireBall(fire_rotation: number) {
        // const radians = fire_rotation * Math.PI / 180;
        // const ball_speed = GameConst.ins().ball_speed + 100 * GameModel.ins().ball_fire_speed;
        // this.getComponent(cc.RigidBody).linearVelocity = cc.v2(Math.sin(radians) * ball_speed, Math.cos(radians) * ball_speed);
        // this.ball_status = EnumBallStatus.onFire;
    }

    onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider) {
        switch (otherCollider.tag) {
            case 1: {
                //底
                if (this.node.active) {
                    this.getComponent(cc.RigidBody).linearVelocity = cc.v2(0, 0);
                }
                break;
            }
        }
    }
}
